package com.pingbu.tijian.hospital.backapi.api;

import com.github.pagehelper.PageInfo;
import com.pingbu.common.bean.ResultBean;
import com.pingbu.tijian.hospital.backapi.bean.entity.Classes;
import com.pingbu.tijian.hospital.backapi.bean.entity.UserInfo;
import com.pingbu.tijian.hospital.backapi.service.ClassesService;
import com.pingbu.tijian.hospital.backapi.service.UserInfoService;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;
import java.util.Date;

@CrossOrigin
@RestController
public class UserInfoController {

    private static Logger logger = LoggerFactory.getLogger(UserInfoController.class);
    @Autowired
    private ClassesService classesService;
    @Autowired
    private UserInfoService userService;

    /**
     * @param param
     * @return
     */
    @PostMapping(value = "/user_info/do_login")
    public ResultBean<UserInfo> do_login(@RequestBody(required = false) UserInfo param) {
        ResultBean<UserInfo> rb = userService.getUserByCodeAndPwd(param);
        return rb;
    }
    /**
     *@Description:用户传来用户id和班级码加入班级
     * @Param param:用户id  班级码
     * @Param classes
     *@Return: com.pingbu.common.bean.ResultBean<java.lang.Integer>
     *@Creator: Rubbish Sen
     *@CreatorTime: 2021/11/30
     */
    @PostMapping(value = "/user_info/UserJoinClass")
    public ResultBean<Integer> UserJoinClass(@RequestBody UserInfo userInfo) {
        Classes classes = new Classes();
        classes.setClass_code(userInfo.getClass_code());
        UserInfo userInfo1 = new UserInfo();
        userInfo1.setNoid(userInfo.getNoid());
        System.out.println(userInfo.getNoid());
        ResultBean<Integer> integerResultBean = classesService.UserJoinClass(userInfo1, classes);
        return integerResultBean;
    }

    /**
     * @param param
     * @return
     */
    @PostMapping(value = "/user_info/page")
    public ResultBean<PageInfo<UserInfo>> page(@RequestBody UserInfo param) {
        ResultBean<PageInfo<UserInfo>> rb = userService.doPage(param);
        return rb;
    }

    /**
     * @param param
     * @return
     */
    @PostMapping(value = "/user_info/add")
    public ResultBean<Integer> add(@RequestBody UserInfo param) {
        ResultBean<Integer> rb = userService.add(param);
        return rb;
    }

    /**
     * @param param
     * @return
     */
    @PostMapping(value = "/user_info/delete")
    public ResultBean<Integer> delete(@RequestBody UserInfo param) {
        ResultBean<Integer> rb = userService.delete(param);
        return rb;
    }

    @PostMapping(value = "/user_info/update")
    public ResultBean<Integer> update(@RequestBody UserInfo param) {
        ResultBean<Integer> rb = userService.update(param);
        return rb;
    }


    @PostMapping(value = "/user_info/validUserCode")
    public ResultBean<Integer> validUserCode(@RequestBody UserInfo param) {
        ResultBean<Integer> rb = userService.validUserCode(param);
        return rb;
    }

}
